package com.eelpo.cmmp.uac.pages.entitytype;

import java.util.Arrays;
import java.util.List;

import com.eelpo.cmmp.core.wicket.panel.container.SearchPanel;
import com.eelpo.cmmp.uac.dao.vo.EntityType;
import com.eelpo.cmmp.uac.dao.vo.enumed.Status;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

/**
 * <pre>
 * 实体类型管理查询参数面板
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class EntityTypeSearchPanel<T> extends SearchPanel {
	private static final long serialVersionUID = -7619742830788988622L;

	public EntityTypeSearchPanel(String id, EntityType type) {
		super(id);

		add(renderFeedbackPanel("feedback"));

		renderTypeNameTextField(type);
		renderTypeCodeTextField(type);
		renderTypeStatusDropDownChoice(type);
		renderAddButton();
	}

	public void renderTypeNameTextField(EntityType type) {
		TextField<String> txtTypeName = new TextField<String>("txtTypeName", new PropertyModel<String>(type, "name"));
		add(txtTypeName);
	}

	public void renderTypeCodeTextField(EntityType type) {
		TextField<String> txtTypeCode = new TextField<String>("txtTypeCode", new PropertyModel<String>(type, "code"));
		add(txtTypeCode);
	}

	public void renderTypeStatusDropDownChoice(EntityType type) {
		List<Status> dataList = Arrays.asList(new Status[] { Status.ENABLED, Status.DISABLED, Status.ALL });
		IModel<Status> model = new PropertyModel<Status>(type, "status");
		IChoiceRenderer<Status> choiceRenderer = new ChoiceRenderer<Status>("label", "value");
		DropDownChoice<Status> actionStatus = new DropDownChoice<Status>("selStatus", model, dataList, choiceRenderer);
		actionStatus.setMarkupId("selStatus");
		add(actionStatus);
	}

	private void renderAddButton() {
		Link<Void> lnkAdd = new Link<Void>("btnAdd") {

			private static final long serialVersionUID = 3804851264584340305L;

			public void onClick() {
				setResponsePage(new AddOrEditEntityType());
			}
		};
		add(lnkAdd);
	}
}
